#pragma once
#include "commom.hpp"

class InitNamePipe
{
public:
    InitNamePipe()
    {
        int n = ::mkfifo(NanedPipe.c_str(), mode);
        if (n == -1)
        {
            std::cerr << "mkfifo fail" << std::endl;
        }
        else
        {
            std::cout << "mkfifo success" << std::endl;
        }
    }
    ~InitNamePipe()
    {
        ::unlink(NanedPipe.c_str());
        std::cout << "unlink success" << std::endl;
    }
};
InitNamePipe inp;

class Server
{
public:
    Server()
    {
    }

    bool openreadpipe()
    {
        _fd=openpipe(READFLAG);
        if(_fd<0)
            return false;
        else
            std::cout<<"open success"<<std::endl; 
        return true;
    }

    bool ReceiveMessage(char* output)
    {
        int n = ::read(_fd, output, bufsize);
        if (n == 0)
            return false;
        output[n]='\0';
        return true;
    }

    bool closepipe()
    {
        ::close(_fd);
        std::cout << "close pipe success" << std::endl;
        return true;
    }

    ~Server()
    {
    }

private:
    int _fd;
};